{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "89.0411467552185\n",
      "{'00000000000000000000000000000000': 478, '11111111111111111111111111111111': 546}\n",
      "backend: aer_simulator_statevector\n"
     ]
    }
   ],
   "source": [
    "from qiskit import QuantumCircuit, transpile\n",
    "from qiskit_aer import Aer\n",
    "import time\n",
    "# from cusvaer.backends import StatevectorSimulator\n",
    "\n",
    "def create_ghz_circuit(n_qubits):\n",
    "    circuit = QuantumCircuit(n_qubits)\n",
    "    circuit.h(0)\n",
    "    for qubit in range(n_qubits - 1):\n",
    "        circuit.cx(qubit, qubit + 1)\n",
    "    return circuit\n",
    "time_1 = time.time()\n",
    "simulator = Aer.get_backend('aer_simulator_statevector')\n",
    "circuit = create_ghz_circuit(n_qubits=32)\n",
    "circuit.measure_all()\n",
    "circuit = transpile(circuit, simulator)\n",
    "job = simulator.run(circuit)\n",
    "result = job.result()\n",
    "time_2 = time.time()\n",
    "print(time_2 - time_1)\n",
    "print(result.get_counts())\n",
    "print(f'backend: {result.backend_name}')\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit import QuantumCircuit, transpile\n",
    "from cusvaer.backends import StatevectorSimulator\n",
    "\n",
    "def create_ghz_circuit(n_qubits):\n",
    "    ghz = QuantumCircuit(n_qubits)\n",
    "    ghz.h(0)\n",
    "    for qubit in range(n_qubits - 1):\n",
    "        ghz.cx(qubit, qubit + 1)\n",
    "    ghz.measure_all()\n",
    "    return ghz\n",
    "\n",
    "circuit = create_ghz_circuit(20)\n",
    "\n",
    "simulator = StatevectorSimulator()\n",
    "simulator.set_options(precision='double')\n",
    "circuit = transpile(circuit, simulator)\n",
    "job = simulator.run(circuit, shots=1024)\n",
    "result = job.result()\n",
    "\n",
    "if result.mpi_rank == 0:\n",
    "    print(result.get_counts())"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "qmg-gpu",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
